package com.pro.common;

import com.pro.utils.MD5Util;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebListener;

/**
 * ClassName:SecurityPasswordEncoder
 * Package:com.pro.security
 * Description:
 *
 * @Date:2021/11/6 17:46
 * @Author: LBF
 */
@WebListener
@WebFilter
public class SecurityPasswordEncoder implements PasswordEncoder {

    /**
     * 加密逻辑
     * @param rawPassword 明文密码，页面传递过来的密码
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
       System.out.println("加密逻辑验证"+rawPassword.toString()+"加密后："+MD5Util.md5(rawPassword.toString()));
        return MD5Util.md5(rawPassword.toString());
    }

    /**
     * 匹配逻辑
     * @param rawPassword  明文密码，页面传递过来的密码
     * @param encodedPassword  密文密码，数据库中的密码
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
//        System.out.println("匹配逻辑验证");
        return encodedPassword.equals(encode(rawPassword));
    }
}
